﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class RoutingSection : BodiedStatement
{
    private StringLiteral? _context;

    internal RoutingSection(SyntaxToken declareKeywordToken, SyntaxNode? parent) :
        base(SyntaxKinds.RoutingSection, parent)
    {
        DeclareKeywordToken = declareKeywordToken;
        DeclareKeywordToken.Parent = this;
    }


    public SyntaxToken DeclareKeywordToken { get; }

    public StringLiteral? Context => _context;


    public RoutingSection Update(StringLiteral context)
    {
        SetChildNullableField(ref _context, context);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken, Context);
        base.AcceptVisitor(visitor);
    }
}


public static partial class NodeFactory
{
    public static RoutingSection CreateRoutingSection(SyntaxNode? parent, SyntaxToken declareKeywordToken,
        StringLiteral? context)
    {
        Debug.Assert(declareKeywordToken.IsNode(SyntaxKinds.RoutingKeywordToken));
        RoutingSection section = new(declareKeywordToken, parent);
        if (context != null)
        {
            section.Update(context);
        }

        return section;
    }
}